﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using SonCa.SocialNetwork.Web.Profiles.IPresenters;
using Core.Common;
using SonCa.SocialNetwork.Web.HelperClass;
using Core.DataAccess;
using System.ComponentModel.Composition;
using Core.BusinessLogic.Interfaces;
using Core.Interfaces;

namespace SonCa.SocialNetwork.Web.Profiles.Presenters
{
    public class ListFriendsChatPresenter
    {
        private IListFriendsChatPresenter _view;
        private List<FriendRequestHelper> _friendRequestHelper;
        [Import]
        private IFriendService _friendService;
        [Import]
        private IUserSession _userSession;
        [Import]
        private IAccountService _accountService;

        public ListFriendsChatPresenter()
        {
            MEFManager.Compose(this);
        }

        public void Init(IListFriendsChatPresenter view)
        {
            _view = view;            
            //int accountID = _userSession.CurrentUser.AccountID;
            //_friendRequestHelper = GetListFriendChat(accountID);
            //_view.DisplayInfo(_friendRequestHelper);
        }

        public List<FriendRequestHelper> GetListFriendChat(int accountID)
        {
            _friendRequestHelper = new List<FriendRequestHelper>();
            List<int> lstAccountIDFriend = new List<int>();

            List<Friend> lstFriends = _friendService.GetFriendsByAccountID(accountID);
            foreach (Friend fr in lstFriends)
            {
                lstAccountIDFriend.Add(fr.AccountID);
                lstAccountIDFriend.Add(fr.MyFriendsAccountID);
            }
            lstAccountIDFriend = lstAccountIDFriend.Distinct().ToList();
            lstAccountIDFriend.Remove(_userSession.CurrentUser.AccountID);
            _accountService.GetAccountsByAccountIDList(lstAccountIDFriend).ForEach(n => _friendRequestHelper.Add(new FriendRequestHelper
            {
                AccountID = n.AccountID,
                FullName = n.LastName + " " + n.MidName + " " + n.FirstName,
                ImageUrl = string.Format("~/Images/ProfileAvatar/ProfileImage.aspx?AccountID={0}", n.AccountID)
            }));
            return _friendRequestHelper;
        }
    }
}